import { ref } from 'vue'
import axios from '../plugins/axios'
import useCommont from './useCommont'
import { showSuccessToast } from 'vant'

export default () => {
   const form = ref<UserModel>()
   const { commontList } = useCommont()
   const updata = () => {}

   const getUserCommontList = async () => {
      return await axios.request<CommontModel[]>({ url: `user/commont` })
   }

   const formPassword = ref<{ oldPassword: string; newPassword: string }>({ oldPassword: '', newPassword: '' })
   const upPassword = async () => {
      try {
         await axios.request({ url: 'user', method: 'Patch', data: formPassword.value })
         showSuccessToast('修改成功')
      } catch (error) {
         return error
      }
   }

   const upUserInfo = async (form: { nickname: string; hobby: string; avatar: string }) => {
      return await axios.request({ url: 'user/upUserInfo', method: 'post', data: form })
   }

   // 添加位置
   const addLocation = async (form: { latitude: number; longitude: number }) => {
      return await axios.request({ url: 'user/location', method: 'post', data: form })
   }

   return { updata, getUserCommontList, commontList, upPassword, formPassword, upUserInfo, addLocation }
}
